package com.luoqiz.design.singleton.type6;

public class SingletonTest06 {
    public static void main(String[] args) {
        Singleton singleton1 = Singleton.getInstance();
        Singleton singleton2 = Singleton.getInstance();

        System.out.println("singleton1 hashcode:" + singleton1.hashCode());
        System.out.println("singleton2 hashcode:" + singleton2.hashCode());
    }
}

//静态内部类  重点推荐   采用类装载机制来保证初始化实例时只有一个线程运行
class Singleton {

    static class SingletonInstance {
        public static final Singleton INSTANCE = new Singleton();
    }
    public static Singleton getInstance() {
        return SingletonInstance.INSTANCE;
    }
}